#include<bits/stdc++.h>
using namespace std;
const int mod = 10;
// 快速幂取模；
typedef long long ll;
int fastPow(ll a, ll n, int mod) {
    int ans = 1;
    while (n) {
        if (n & 1) ans = ((ans % mod) * (a % mod)) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    while (N--) {
        ll k;
        cin >> k;
        cout << fastPow(k % mod, k, mod) << endl;
    }
    return 0;
}